using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SettingsDialog : DialogBase
{
    [SerializeField] private Slider musicSlider;
    [SerializeField] private Slider sfxSlider;
    private AudioSource musicSource;
    //private AudioSource sfxSource;

    private void Start()
    {
        musicSource = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<AudioSource>();
        //if (GameObject.FindGameObjectWithTag("AudioManager"))
          //  sfxSource = GameObject.FindGameObjectWithTag("AudioManager").GetComponent<AudioSource>();
        SetFormData();
        musicSlider.onValueChanged.AddListener(MusicChanged);
        //sfxSlider.onValueChanged.AddListener(SFXChanged);
    }

    private void SetFormData()
    {
        DataManager.Instance.LoadSettings();
        musicSlider.value = DataManager.Instance.MusicSettingValue;
        musicSource.volume = DataManager.Instance.MusicSettingValue;
        //sfxSlider.value = DataManager.Instance.SFXSettingValue;
    }

    private void MusicChanged(float value)
    {
        musicSource.volume = musicSlider.value;
        DataManager.Instance.MusicSettingValue = value;
        DataManager.Instance.SaveSettings();
    }

    /*private void SFXChanged(float value)
    {
        sfxSource.volume = value;
        DataManager.Instance.SFXSettingValue = value;
        DataManager.Instance.SaveSettings();
    }*/
}
